package com.yz.xyt.controller;

import com.yz.xyt.constant.HttpStatus;
import com.yz.xyt.domain.Major;
import com.yz.xyt.domain.ResponseResult;
import com.yz.xyt.domain.vo.MajorVo;
import com.yz.xyt.service.IBaseDataImportService;
import com.yz.xyt.service.IMajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 专业管理
 * @author JW.WANG
 */
@RestController
@RequestMapping("/system")
public class MajorManagerController {

    @Autowired
    IBaseDataImportService baseDataImportService;

    @Autowired
    IMajorService majorService;

    /**
     * 专业excel导入
     * @param file
     * @return
     */
    @RequestMapping("importMajor")
    public ResponseResult importMajor(MultipartFile file){
        ResponseResult result = baseDataImportService.importMajor(file);
        return result;
    }

    /**
     * 分页查询专业
     * @param majorVo
     * @return
     */
    @RequestMapping("/findMajorPage")
    public ResponseResult findMajorPage(MajorVo majorVo){
        ResponseResult result = new ResponseResult();
        try {
            result = majorService.findMajorPage(majorVo);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(HttpStatus.ERROR);
            result.setMsg("分页查询专业失败");
        }
        return result;
    }

    /**
     * 查询专业列表
     * @param majorVo
     * @return
     */
    @RequestMapping("/findMajorList")
    public ResponseResult findMajorList(MajorVo majorVo){
        ResponseResult result = new ResponseResult();
        try {
            result = majorService.findMajorList(majorVo);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(HttpStatus.ERROR);
            result.setMsg("查询专业失败");
        }
        return result;
    }

    /**
     * 新增专业
     * @param major
     * @return
     */
    @RequestMapping("/addMajor")
    public ResponseResult addMajor(Major major){
        ResponseResult result = new ResponseResult();
        try {
            result = majorService.addMajor(major);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(HttpStatus.ERROR);
            result.setMsg("新增专业失败");
        }
        return result;
    }

    /**
     * 删除专业
     * @param majorVo
     * @return
     */
    @RequestMapping("/deleteMajor")
    public ResponseResult deleteMajor(MajorVo majorVo){
        ResponseResult result = new ResponseResult();
        try {
            result = majorService.deleteMajor(majorVo);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode(HttpStatus.ERROR);
            result.setMsg("删除专业失败");
        }
        return result;
    }
}
